﻿using BlogDemo.Core.Domain;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;

namespace BlogDemo.Infrastructure
{
    internal static class BlogSeedData
    {
        static int blogId = 1;
        static int Tag_id1 = 1;
        static int Tag_id2 = 2;
        internal static EntityTypeBuilder HasDataBlogSeed(this EntityTypeBuilder builder)
        {

            var blog = new Blog() { Id = blogId, Name = "My Blogs", Url = "yourqq2009.qzone.qq.com" };

            builder.HasData(blog);
            return builder;
        }

        internal static EntityTypeBuilder HasDataTagSeed(this EntityTypeBuilder builder)
        {
            var tags = new List<Tag>() {
                new Tag() { Id = Tag_id1, Name = "asp.net" },
                new Tag() { Id = Tag_id2, Name = "javascript" },
             };

            builder.HasData(tags);
            return builder;
        }
        internal static EntityTypeBuilder HasDataPostTagSeed(this EntityTypeBuilder<PostTag> builder)
        {
            var postTags = new List<PostTag>();
            for (int i = 1; i <= 10; i++)
            {
                postTags.Add(new PostTag() { TagId = Tag_id1, PostId = i });
                postTags.Add(new PostTag() { TagId = Tag_id2, PostId = i });
            }
            builder.HasData(postTags);

            return builder;
        }
        internal static EntityTypeBuilder HasDataPostSeed(this EntityTypeBuilder<Post> builder)
        {
            var posts = new List<Post>();
            for (int i = 1; i <= 10; i++)
            {
                //postTags.Add(new PostTag() { TagId = Tag_id1, PostId = i });
                posts.Add(new Post() { BlogId = blogId, Id = i, Title = $"A Title {i}", Body = "BlogDbContext:HasData：Extensions", Author = "未知", CreateAt = DateTime.Now });

            }
            builder.HasData(posts);

            return builder;
        }

        #region permissionIds
        private static Guid permissionId_01 = Guid.NewGuid();
        private static Guid permissionId_02 = Guid.NewGuid();
        private static Guid permissionId_03 = Guid.NewGuid();
        private static Guid permissionId_04 = Guid.NewGuid();
        private static Guid permissionId_05 = Guid.NewGuid();
        private static Guid permissionId_06 = Guid.NewGuid();
        private static Guid permissionId_07 = Guid.NewGuid();
        private static Guid permissionId_08 = Guid.NewGuid();
        private static Guid permissionId_09 = Guid.NewGuid();
        private static Guid permissionId_10 = Guid.NewGuid();
        private static Guid permissionId_11 = Guid.NewGuid();
        private static Guid permissionId_12 = Guid.NewGuid();
        private static Guid permissionId_13 = Guid.NewGuid();

        #endregion

        #region roleId
        private static Guid roleId_01 = Guid.NewGuid();
        private static Guid roleId_02 = Guid.NewGuid();

        #endregion 

        /*  public static EntityTypeBuilder HasDataPermissionSeed(this EntityTypeBuilder builder)
          {
              var permissions = new List<PermissionSeed>()
              {
                  new PermissionSeed(){ ID = permissionId_01,ControllerName="",ActionName="",IsDisabled=0,OrderIndex=0,Description=@"系统管理" },
                  new PermissionSeed(){ ID = permissionId_02,ControllerName="",ActionName="",IsDisabled=0,OrderIndex=1,Description=@"组织架构" },
                  new PermissionSeed(){ ID = permissionId_03,ControllerName="",ActionName="",IsDisabled=0,OrderIndex=2,Description=@"内容管理" },
                  new PermissionSeed(){ ID = permissionId_04,ControllerName="",ActionName="",IsDisabled=0,OrderIndex=3,Description=@"统计报表" },

                  new PermissionSeed(){ ID = permissionId_05,ParentPermissionID=permissionId_01,ControllerName="SystemSetting",ActionName="Index",IsDisabled=0,OrderIndex=0,Description=@"系统设置" },
                  new PermissionSeed(){ ID = permissionId_06,ParentPermissionID=permissionId_01,ControllerName="SystemSetting",ActionName="Other",IsDisabled=0,OrderIndex=1,Description=@"其他设置" },

                  new PermissionSeed(){ ID = permissionId_07,ParentPermissionID=permissionId_02,ControllerName="PermissionManager",ActionName="Index",IsDisabled=0,OrderIndex=0,Description=@"权限管理" },
                  new PermissionSeed(){ ID = permissionId_08,ParentPermissionID=permissionId_02,ControllerName="RoleManager",ActionName="Index",IsDisabled=0,OrderIndex=1,Description=@"角色管理" },
                  new PermissionSeed(){ ID = permissionId_09,ParentPermissionID=permissionId_02,ControllerName="UserManager",ActionName="Index",IsDisabled=0,OrderIndex=2,Description=@"用户管理" },

                  new PermissionSeed(){ ID = permissionId_10,ParentPermissionID=permissionId_03,ControllerName="ArticleManager",ActionName="Index",IsDisabled=0,OrderIndex=0,Description=@"文章管理" },
                  new PermissionSeed(){ ID = permissionId_11,ParentPermissionID=permissionId_03,ControllerName="VideoManager",ActionName="Index",IsDisabled=0,OrderIndex=1,Description=@"视频管理" },

                  new PermissionSeed(){ ID = permissionId_12,ParentPermissionID=permissionId_04,ControllerName="TongJiManager",ActionName="Index",IsDisabled=0,OrderIndex=0,Description=@"统计管理" },
                  new PermissionSeed(){ ID = permissionId_13,ParentPermissionID=permissionId_04,ControllerName="BaoBiaoManager",ActionName="Index",IsDisabled=0,OrderIndex=0,Description=@"报表管理" },
              };
              builder.HasData(permissions.ToArray());
              return builder;
          }

          public static EntityTypeBuilder HasDataRole(this EntityTypeBuilder builder)
          {
              var roles = new List<UserRole>() {
                  new UserRole(){ID = roleId_01,RoleName = @"超级管理员",IsDisabled = Entity.Enums.IsDisabled.UnDisable,CreateTime = DateTime.Now},
                  new UserRole(){ID = roleId_02,RoleName = @"管理员",IsDisabled = Entity.Enums.IsDisabled.UnDisable,CreateTime = DateTime.Now}
              };
              builder.HasData(roles.ToArray());
              return builder;
          }

          public static EntityTypeBuilder HasDataRolePermission(this EntityTypeBuilder builder)
          {

              var rolePermissions = new List<UserRolePermission>()
              {
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_01,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_02,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_03,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_04,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_05,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_06,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_07,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_08,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_09,UserRoleID = roleId_01}  ,
                  new UserRolePermission(){ID = Guid.NewGuid(),PermissionSeedID = permissionId_10,UserRoleID = roleId_01}
              };
              builder.HasData(rolePermissions.ToArray());
              return builder;
          }
          public static EntityTypeBuilder HasDataUser(this EntityTypeBuilder builder)
          {
              var users = new List<User>() {
                  new User(){ID = Guid.NewGuid(),CreateTime = DateTime.Now,Gender = Entity.Enums.GenderEnum.Man,HeadImage="",
                      IsDisabled = Entity.Enums.IsDisabled.UnDisable,LoginAccount = "thomas",LoginPassword="123qwe",NickName="thomas",
                      Remark = "seed初始化种子数据",Telphone="15251820632",UserRoleID = roleId_01,UserEctensionID=userExtensionId_01
                  },
                  new User(){ID = Guid.NewGuid(),CreateTime = DateTime.Now,Gender = Entity.Enums.GenderEnum.Man,HeadImage="",
                      IsDisabled = Entity.Enums.IsDisabled.UnDisable,LoginAccount = "thomas",LoginPassword="123qwe",NickName="thomas",
                      Remark = "seed初始化种子数据",Telphone="15251820632",UserRoleID = roleId_01,UserEctensionID=userExtensionId_01
                  },
              };
              builder.HasData(users.ToArray());
              return builder;
          }*/
    }
}
